<?php

namespace app\manystore\model;

use think\Model;


class CampusMallOrder extends Model
{

    

    

    // 表名
    protected $name = 'campus_mall_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'distribution_text',
        'status_text',
        'pay_type_text',
        'pay_time_text',
        'refund_status_text',
        'refund_time_text',
        'review_status_text',
        'create_time_text',
        'update_time_text',
        'is_show_text',
        'assemble_status_text',
        'auto_recv_time_text'
    ];
    

    
    public function getDistributionList()
    {
        return ['0' => __('Distribution 0'), '1' => __('Distribution 1')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'),'2' => __('Status 2'),'3' => __('Status 3'),'4' => __('Status 4'),'10' => __('Status 10')];
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '6' => __('Status 6')];
    }

    public function getPayTypeList()
    {
        return ['0' => __('Pay_type 0'), '2' => __('Pay_type 2'), '3' => __('Pay_type 3'), '1' => __('Pay_type 1')];
    }

    public function getRefundStatusList()
    {
        return ['0' => __('Refund_status 0'), '1' => __('Refund_status 1'), '2' => __('Refund_status 2'), '3' => __('Refund_status 3'), '4' => __('Refund_status 4')];
    }

    public function getReviewStatusList()
    {
        return ['0' => __('Review_status 0'), '1' => __('Review_status 1')];
    }

    public function getIsShowList()
    {
        return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
    }

    public function getAssembleStatusList()
    {
        return ['0' => __('Assemble_status 0'), '1' => __('Assemble_status 1'), '2' => __('Assemble_status 2'), '3' => __('Assemble_status 3')];
    }


    public function getDistributionTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['distribution']) ? $data['distribution'] : '');
        $list = $this->getDistributionList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRefundStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
        $list = $this->getRefundStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRefundTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_time']) ? $data['refund_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReviewStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['review_status']) ? $data['review_status'] : '');
        $list = $this->getReviewStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsShowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
        $list = $this->getIsShowList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAssembleStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['assemble_status']) ? $data['assemble_status'] : '');
        $list = $this->getAssembleStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAutoRecvTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['auto_recv_time']) ? $data['auto_recv_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPayTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setRefundTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAutoRecvTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function campusmallordergoods()
    {
        //等前端改的时候，注释行对调，现在先展示子订单
//        return $this->hasMany('CampusMallOrderGoods','order_id');
        return $this->belongsTo('CampusMallOrderGoods', 'id', 'order_id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('User', 'mid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function userinfo()
    {
        return $this->belongsTo('UserInfo', 'mid', 'u_id', [], 'LEFT')->setEagerlyType(0);
    }
}
